var curUserID = 0;
var UserInfo = "";
var SpaceURL = "";
$(document).ready(function () {
    $.getJSON("http://interface.baomihua.com/userapi.asmx/GetCurrentLoginUserInfo?jsoncallback=?", { flag: "json" }, function (json) {
        if (typeof (json.UserInfoList) != "undefined") {
            UserInfo = json.UserInfoList[0];
            SpaceURL = UserInfo.SpaceURL;
            curUserID = UserInfo.UserId;
        }
        $.each($('.bVideo .star_detail .showblock dl dd .widget'), function (i, n) {
            var tempVideoID = $(n).attr("vid");
            var tempVideoPic = $(n).attr("pic");
            var tempUserSpace = $(n).attr("space");
            var tempVideoTitle = $(n).attr("name");
            if (SpaceURL != "") {
                tempUserSpace = SpaceURL;
            }
            Pui.www.shareLink(tempVideoID, tempVideoPic, tempUserSpace, tempVideoTitle);
        });
    });
   
});
Pui.www = {
    hoverShow: function (a, b, c, fFuna, fFunb) {
        var rank = $(a);
        rank.hover(function () {
            if (typeof c != 'undefined') {
                $(c).show();
            }
            else {
                rank.removeClass(b);
                $(this).addClass(b);
            }
            if (fFuna instanceof Function) fFuna();
        }, function () {
            if (typeof c != 'undefined') {
                $(c).hide();
            }
            if (fFuna instanceof Function) fFunb();
        });
    },
    tab: function () {
        var o_li = $('.bVideo .hot_search .shoulder a');
        o_li.hover(function () {
            var _self = $(this);
            if (_self.parent().children().length <= 1) return false;
            _self.addClass('ac').siblings().removeClass('ac');
            var index = _self.parent().children().index(_self[0]);
            $('.bVideo .hot_search .showblock').css('display', 'none').eq(index).css('display', 'block');
            return false;
        }, function () { }).click(function () { return false; });
    },
    shareLink: function (tempVideoID, tempVideoPic, tempUserSpace, tempVideoTitle) {
        var t = this;
      
        var flvid = tempVideoID;
        var pic = tempVideoPic;
        var vTitle = encodeURIComponent(tempVideoTitle.replace(/(^\s*)|(\s*$)/g, ""));
        var vLink = encodeURIComponent('http://video.baomihua.com/' + tempUserSpace + '/' + flvid);
        var vContent = encodeURIComponent('http://video.pomoho.com/swf/out_player.swf?flvid=' + flvid);
        var vBogo = encodeURIComponent('http://video.baomihua.com/' + tempUserSpace + '/' + flvid);
        var vSource = encodeURIComponent('爆米花网');
        var vSourceUrl = encodeURIComponent('http://www.baomihua.com/');
        var s = '<a id=\"QQ_T\" href=\"http://v.t.qq.com/share/share.php?url=' + vLink + '&appkey=6fecfd1d14b14aaeba7982c69e96d0d3&site=' + vLink + '&pic=' + pic + '&title=' + vTitle + '\" target=\"_blank\" title=\"腾讯微博\">分享到腾讯微博</a>';
        s += '<a id=\"QQ\" href=\"http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + vLink + '&title=' + vTitle + '&charset=utf-8\" target=\"_blank\" title=\"QQ空间\">分享到QQ空间</a>';
        s += '<a id=\"renren\" href=\"http://share.renren.com/share/buttonshare.do?link=' + vLink + '&title=' + vTitle + '\" target=\"_blank\" title=\"分享至人人网\">分享到人人网</a>';
        s += '<a id=\"kaixin\" href=\"http://www.kaixin001.com/repaste/share.php?rurl=' + vLink + '&rcontent=' + vLink + '&rtitle=' + vTitle + '\" target=\"_blank\" title=\"分享至开心网\">分享到开心网</a>';
        s += '<a id=\"sina\"  href=\"http://v.t.sina.com.cn/share/share.php?c=spr_web_bd_pomoho_weibo&url=' + vLink + '&title=' + vLink + '&source=' + vSource + '&sourceUrl=' + vSourceUrl + '&appkey=2523263809&pic=' + pic + '\" target=\"_blank\" title=\"分享至新浪微博\">分享到新浪微博</a>';
        s += "<a id=\"itieba\" href=\"http://tieba.baidu.com/i/sys/share?link=" + vLink + '&type=video&title=' + vTitle + '&content=' + vContent + "\" title=\"分享至i贴吧\" target=\"_blank\">分享到i贴吧</a>";
        s += "<a id=\"sohu\" href=\"http://t.sohu.com/third/post.jsp?url=" + vLink + "&pic=" + pic + "&title=" + vTitle + "&content=utf-8\"   target=\"_blank\" title=\"分享到搜狐微博\">分享到搜狐微博</a>";
        // var s = '<a class="" id="wuyicom" href="http://share.51.com/share/out_share_video.php?vaddr=' + vBogo + '&title=' + vTitle + '&charset=utf-8&from=baomihua" target="_blank" title="51交友社区">转贴至51交友社区</a><a id="QQ" href="http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + vLink + '&title=' + vTitle + '&charset=utf-8" target="_blank" title="QQ空间">转贴至QQ空间</a><a id="renren" href="http://share.renren.com/share/buttonshare.do?link=' + vLink + '&title=' + vTitle + '" target="_blank" title="转贴至人人网">转贴至人人网</a><a id="kaixin" href="http://www.kaixin001.com/repaste/share.php?rurl=' + vLink + '&rcontent=' + vLink + '&rtitle=' + vTitle + '" target="_blank" title="转贴至开心网">转贴至开心网</a><a id="sina" href="http://v.t.sina.com.cn/share/share.php?c=spr_web_bd_pomoho_weibo&url=' + vLink + '&title=' + vTitle + '&source=' + vSource + '&sourceUrl=' + vSourceUrl + '&appkey=1854178289&pic=' + pic + '" target="_blank" title="转贴至新浪微博">转贴至新浪微博</a><a id="itieba" href="" title="转贴至i贴吧">转贴至i贴吧</a>';
        $(s).appendTo($('<span class="icos"></span>').appendTo($("#video_" + tempVideoID + ' .tospace'))).click(function () {
            t.videoLink(flvid);
           //if ($(this).attr('id') === 'itieba') { alert(''); itieba(vLink, vTitle, vContent); }
        });
    },
    strLen: function (a, b) {
        $(a).each(function () {
            var t = $(this);
            t.html(t.html().toString().strLen(b));
        });
    },
    videoLink: function (a) {
        if (IsLogin) {
            var b = {
                imdbid: a,
                userID: userID
            };
            $.ajax({
                type: "get",
                url: "http://www.baomihua.com/interfaces/VideoLinks.ashx",
                data: b,
                dataType: "jsonp",
                jsonp: "jsoncallback",
                timeout: 300000,
                success: function (e) {
                    if (e.Result == '-2') {
                        Pui.header.loginfo2()
                    } else {
                        //						alert(e.Msg)
                    }
                }
            })
        }
        else {
            alert("您还没有登录，转贴视频不会产生收入！");
        }
    }
}
Pui.www.index={
	init:function(){
		Pui.header.init();
		Pui.searching.init();
		Pui.autoThumb('.commend_video .vimg img,.popular_video .vimg img,.original_video .vimg img',120,90);
		Pui.autoThumb('.commend_org .vimg img',90,90);
		this.addNum();
		//this.crossDomain();
		//this.deEscape('.hotsearch li a');
		Pui.searching.Searched.init();
		this.StripeTables();
		//Pui.searching.keyWords.keyWords_show();		
	},
	addNum:function(){
		var n=0;ol=$('.hotsearch ol').length;
		while(n<ol){
			$('.hotsearch ol').eq(n).find('li').each(
				function(i){
					$('<span>'+[i+1]+'</span>').prependTo($('.hotsearch ol').eq(n).find('li')[i]);
				}							  
			);
			n++;
		}
		$('#FootLogo a:last-child').find('img').css({'height':50,'width':45});
	},
	crossDomain:function(){
		document.domain='pomoho.com';
		$('<iframe style="position:absolute;z-index:-1;border:none;width:0;height:0;" id="autoCompleteShow" name="autoCompleteShow" src="http://search.pomoho.com/autoComplete.html"></iframe>').appendTo($('.header1 .header_main'));	
	},
	deEscape:function(a){
		$(a).each(function(){
		var norUrl=$(this).attr('href').split('_keyword=')[0];
		var norParam=$(this).attr('href').split('_keyword=')[1];
		if(/&/.test(norParam)){
		var norKey=unescape(norParam.split('&')[0]);
		var norT=norParam.split('&')[1];
		$(this).attr('href',norUrl+'_keyword='+encodeURIComponent(norKey)+'&'+norT);}
		else{$(this).attr('href',norUrl+'_keyword='+encodeURIComponent(unescape(norParam)));}								   
		});	
	},
	StripeTables:function(){
		var odd = false;
		var rows =$('#VideoList .meat .row');
		for (var j=0;j<rows.length;j++) {
			if (odd == true) {
				rows.eq(j).css({background: "#ECEBFF"});
				odd = false;
			}else{
					odd = true;
				}
		}
	}
}
Pui.www.cjMedia={
	init:function(){
		Pui.header.init();
		Pui.searching.init();
		this.menuHover();
		Pui.widget.focusTurn('slide',{'mode':'thumb','distance':-550,'width':550,'height':310,'speed':300,'timer':3000});
		Pui.www.hoverShow('.koreatv_rank dl','ac');Pui.www.hoverShow('.video_rank dl','ac');
		Pui.www.strLen('.picshow .desc',86);	
	},
	menuHover:function(){
		var oMl=$('#menu li'),nAc=$('#menu li.ac')[0];
		if(typeof nAc!='undefined'){
			oMl.hover(function(){
				$(this).addClass('ac');	
			},function(){
				oMl.not(nAc).removeClass('ac');	
			});
		}	
	}	
}
Pui.www.channel = {
    init: function () {
        Pui.header.init();
        Pui.searching.init();
        Pui.widget.focusTurn('slide', { 'mode': 'simple', 'distance': -667, 'width': 662, 'height': 330, 'speed': 300, 'timer': 3000 });
        //Pui.www.hoverShow('.enjoining dl','ac');
        //Pui.www.strLen('.bVideo .hotopic .showblock ul .vpop .pop',2);	
        //Pui.www.strLen('.bVideo .hotopic .showblock ul .vpop .comm',1);
        Pui.www.hoverShow('.header3 #nav .checklist,.header3 #nav .channel_maps', 'ac', '.header3 #nav .channel_maps', function () { $('.header3 #nav .checklist').css('border-bottom', '1px solid #fff'); }, function () { $('.header3 #nav .checklist').css('border', '1px solid #ccc'); });
        Pui.www.strLen('.bVideo .picshow .focus h2', 30);
        
       
        Pui.www.tab();
        Pui.www.strLen('.bVideo .hot_search .showblock dl dd .data', 4);
        Pui.www.strLen('.bVideo .star_detail .showblock dl dd .widget .pop,.bVideo .star_detail .showblock dl dd .widget .user a', 6);
        Pui.autoThumb('.bVideo .cooper_boker .showblock dl dt .avatar img', 104, 104);
    }
}